package com.alog.yzd.bookmall.utils;

import com.alog.yzd.bookmall.pager.Expression;

import java.util.List;

public class SqlUtil {

    /**
     * 拼接Where子句
     * @param exps
     * @param params
     * @return
     */
    public static String createWhereSql(List<Expression> exps, List<Object> params){
        StringBuilder whereSql = new StringBuilder(" where 1 = 1");
        for(Expression exp : exps){
            whereSql.append(" and ").append(exp.getName()).append(" ").append(exp.getOperator()).append(" ");
            if(!exp.getOperator().equals("is null")){
                whereSql.append("?");
                params.add(exp.getValue());
            }
        }
        return whereSql.toString();
    }
}
